package com.mfg.service.Impl;

import com.mfg.mappers.WalletMapper;
import com.mfg.pojo.Wallet;
import com.mfg.service.WalletService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
public class WalletServiceImpl implements WalletService {

    @Resource
    private WalletMapper walletMapper;

    public BigDecimal getMoneyInWallet(Integer userId) {
        return walletMapper.getMoneyInWallet(userId);
    }

    public boolean consumeHundred(Integer userId, BigDecimal decreaseMoney) {
        return walletMapper.decreaseMoneyInWallet(userId, decreaseMoney) > 0 ? true : false;
    }

    public Wallet getMoneyAndIdByUserId(Integer userId) {
        return walletMapper.getMoneyAndIdByUserId(userId);
    }

    public boolean refundToWallet(Wallet wallet) {
        boolean res = walletMapper.refundToWallet(wallet) > 0 ? true : false;
        return res;
    }


}
